// 封装获取频道列表的逻辑
import { useState, useEffect } from 'react'
import { getChannelAPI } from '@/apis/article'

function useChannel(){
  // 获取频道列表
  const [ channelList, setChannelList ] = useState([])

  useEffect(() => {
    // 封装获取channelList函数
    const getChannelList = async () => {
      const res = await getChannelAPI()
      setChannelList(res.data.channels)
    }
    // 调用函数
    getChannelList()
  }, [])
  // 把组件中需要的数据return出去
  return{
    channelList
  }
}
export { useChannel }